<?php

namespace app\common\util\plug;

use app\common\util\base\BaseObserver;
use app\common\util\base\BaseServer;
use Symfony\Component\Yaml\Yaml;

class PlugLoadConfig extends BaseObserver
{
    public function handle()
    {
        $path = $this->server->getPlugTempPath();
        $configFile = $path.'v-plug.yaml';
        // 设置配置文件
        $plugInfo = Yaml::parseFile($configFile);
        $realPlugPath = root_path('app').'plug/'.$plugInfo['author'].'_'.$plugInfo['name'];
        copy($configFile, $realPlugPath.'/v-plug.yaml');
        $this->server->setPlugPath($realPlugPath)->setPlugInfo($plugInfo);
        trace($plugInfo, '配置项已载入...');
        return $plugInfo;
    }
}